/**
 * @file Assignment_E.cpp
 * @brief 
 * @author htli (3180102114@zju.edu.cn)
 * @version 1.0
 * @date 2021-10-03
 * 
 * @copyright Copyright (c) 2021  linhuo2020
 * 
 */
#include "NewtonSolver.h"
#include "SecantSolver.h"
#include "BisectionSolver.h"
const double r = 1;
const double L = 10;
const double V = 12.4;
const double _tolerance = 5e-3;
const double _min_width = 1e-2;
double f(const double h)
{
    return L * (0.5 * M_PI * r * r - r * r * asin(h / r) - h * sqrt(r * r - h * h)) - V;
};

double df(const double h)
{
    return -2.0 * L * sqrt(r * r - h * h);
}

void display(const double h)
{
    std::cout<<"The depth is "<<r-h<<" ."<<std::endl;
};

int main()
{
    std::cout << "E." << std::endl;
    BisectionSolver A(f);
    A.set_init(0, r);
    A.set_tolerance(_tolerance);
    A.set_min_width(_min_width);
    display(A.solve());
    NewtonSolver B(f, df);
    B.set_init(0);
    B.set_tolerance(_tolerance);
    display(B.solve());
    SecantSolver C(f);
    C.set_init(0, r);
    C.set_tolerance(_tolerance);
    C.set_min_width(_min_width);
    display(C.solve());
};